var 潜能列表 = [
    [40603, "攻击BOSS时伤害：+40%", 1],
    [40292, "无视怪物40%的防御率", 1],
    [40051, "攻击力：+12%", 1],
    [60001, "总伤害：+12%", 1],
    [60002, "所有属性：+20%", 1],
    [40045, "MaxHP : +12%", 1],
    [40052, "魔法攻击力：+12%", 1],
    [40055, "爆击率 12%", 1],
    [40057, "暴击伤害 8%", 1],
    [40557, "所有技能冷却时间：-2秒", 1]
];
var status = -1;
var selectionLog = [];

function start() {
    action(1, 0, 0)
}

function action(mode, type, selection) {
    var NPC立绘组 = cm.getConstantScriptContent("菜单_NPC立绘");
    var index = Math.floor(Math.random() * NPC立绘组.length);
    var NPC = NPC立绘组[index][0];
    var face = randomNum(0, NPC立绘组[index][1]);
    if (cm.getzhizunvip() != 2) {
        cm.dispose();
        cm.playerMessage(1, "该菜单是至尊版专享。");
        return
    }
    var 装备栏1格 = cm.getEquipBySlot(1);
    if (装备栏1格 == null) {
        cm.dispose();
        cm.getTopMsgFont("装备栏第1格为空？", 3, 20, 4, 0, 0);
        return
    } else {
        var 装备图标 = cm.getInventory(1).getItem(1).getItemId()
    }
    if (status <= 0 && mode == 0) {
        cm.dispose();
        return
    }
    if (status >= 0 && mode == 0) {
        cm.dispose();
        cm.openNpc(9110002, "蜡笔潜能_至尊版");
        return
    }(mode == 1) ? status++ : status--;
    selectionLog[status] = selection;
    var i = -1;
    if (status <= i++) {
        cm.dispose()
    } else {
        if (status === i++) {
            var text = "#face" + face + "##fn方正粗黑宋简体#";
            text += "     #fs17##r欢迎使用 " + cm.getServerName() + " 蜡笔潜能#fs15##k\r\n";
            text += "      #g#v" + 装备图标 + "##z" + 装备图标 + "##k 请选择想要调整的潜能：\r\n#b";
            text += "   #L1##v" + 3994417 + "#基本潜能[1]#l  #L2##v" + 3994418 + "#基本潜能[2]#l  #L3##v" + 3994419 + "#基本潜能[3]#l\r\n";
            text += "   #L4##v" + 3994420 + "#附加潜能[1]#l  #L5##v" + 3994421 + "#附加潜能[2]#l  #L6##v" + 3994422 + "#附加潜能[3]#l\r\n";
            cm.askMenu_Bottom(text, 204, NPC)
        } else {
            var reactor = "action" + selectionLog[1];
            eval(reactor)(mode, type, selection, i)
        }
    }
}

function action0(d, c, b, a) {
    if (status <= a++) {
        cm.dispose()
    }
}

function action1(f, k, n, d) {
    var l = cm.getConstantScriptContent("菜单_NPC立绘");
    var g = Math.floor(Math.random() * l.length);
    var b = l[g][0];
    var j = randomNum(0, l[g][1]);
    var h = 1;
    var m = 1;
    var c = 3994417;
    if (status <= d++) {
        var a = "#face" + j + "##fn方正粗黑宋简体#";
        a += "  #r基本潜能[1]  #z" + c + "#[" + cm.getItemQuantity(c) + "]#k#fs15#";
        for (var d = 0; d < 潜能列表.length; d++) {
            a += "\r\n#L" + d + "#" + 潜能列表[d][1] + "#k  (消耗： #r" + 潜能列表[d][2] + "#k #k 红色蜡笔)#l"
        }
        cm.askMenu_Bottom(a + " \r\n ", 204, b)
    } else {
        if (status === d++) {
            var o = cm.getEquipBySlot(m);
            if (o == null || o.getGrade(false) != 20) {
                cm.askAcceptDecline_Bottom("#face" + j + "出现错误: \r\n\r\n1、请把#b材料#k放在装备栏#r1#k号位。\r\n2、装备的#b潜能等级#k必须为#rSS#k级。", 204, b);
                cm.dispose();
                return
            }
            var e = 潜能列表[n];
            if (e != null) {
                潜能ID = e[0];
                潜能描述 = e[1];
                费用 = e[2];
                Gitem = cm.getInventory(1).getItem(1);
                cm.askYesNo_Bottom("#face" + j + "#当前选择：#g#v" + Gitem.getItemId() + "##z" + Gitem.getItemId() + "##k \r\n\r\n第#r" + h + "#k条潜能改为：#b[" + 潜能描述 + "#k] 吗？", 204, b)
            } else {
                cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                cm.dispose();
                return
            }
        } else {
            if (status === d++) {
                if (cm.getItemQuantity(c) < 1) {
                    cm.getTopMsgFont("缺少货币无法使用服务。", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
                if (潜能ID <= 0 || 潜能描述 == "" || 费用 <= 0) {
                    cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
                if (cm.changePotential(m, h, 潜能ID, false)) {
                    Gitem = cm.getInventory(1).getItem(1);
                    GID = Gitem.getItemId();
                    ii = cm.getItemInfo();
                    cm.gainItem(c, -1);
                    cm.worldSpouseMessage(37, "【蜡笔潜能】：土豪“" + cm.getPlayer().getName() + "”将『" + cm.getItemName(GID) + "』第[" + h + "]条潜能修改为：" + 潜能描述 + " ");
                    cm.getTopMsgFont("系统提示：修改潜能成功!", 3, 20, 20, 0);
                    cm.effect_NormalSpeechBalloon("修改潜能完毕!", 1, 0, 0, 3000, 0, 0);
                    cm.dispose();
                    return
                } else {
                    cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
            }
        }
    }
}

function action2(f, k, n, d) {
    var l = cm.getConstantScriptContent("菜单_NPC立绘");
    var g = Math.floor(Math.random() * l.length);
    var b = l[g][0];
    var j = randomNum(0, l[g][1]);
    var h = 2;
    var m = 1;
    var c = 3994418;
    if (status <= d++) {
        var a = "#face" + j + "##fn方正粗黑宋简体#";
        a += "  #r基本潜能[1]  #z" + c + "#[" + cm.getItemQuantity(c) + "]#k#fs15#";
        for (var d = 0; d < 潜能列表.length; d++) {
            a += "\r\n#L" + d + "#" + 潜能列表[d][1] + "#k  (消耗： #r" + 潜能列表[d][2] + "#k #k 红色蜡笔)#l"
        }
        cm.askMenu_Bottom(a + " \r\n ", 204, b)
    } else {
        if (status === d++) {
            var o = cm.getEquipBySlot(m);
            if (o == null || o.getGrade(false) != 20) {
                cm.askAcceptDecline_Bottom("#face" + j + "出现错误: \r\n\r\n1、请把#b材料#k放在装备栏#r1#k号位。\r\n2、装备的#b潜能等级#k必须为#rSS#k级。", 204, b);
                cm.dispose();
                return
            }
            var e = 潜能列表[n];
            if (e != null) {
                潜能ID = e[0];
                潜能描述 = e[1];
                费用 = e[2];
                Gitem = cm.getInventory(1).getItem(1);
                cm.askYesNo_Bottom("#face" + j + "#当前选择：#g#v" + Gitem.getItemId() + "##z" + Gitem.getItemId() + "##k \r\n\r\n第#r" + h + "#k条潜能改为：#b[" + 潜能描述 + "#k] 吗？", 204, b)
            } else {
                cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                cm.dispose();
                return
            }
        } else {
            if (status === d++) {
                if (cm.getItemQuantity(c) < 1) {
                    cm.getTopMsgFont("缺少货币无法使用服务。", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
                if (潜能ID <= 0 || 潜能描述 == "" || 费用 <= 0) {
                    cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
                if (cm.changePotential(m, h, 潜能ID, false)) {
                    Gitem = cm.getInventory(1).getItem(1);
                    GID = Gitem.getItemId();
                    ii = cm.getItemInfo();
                    cm.gainItem(c, -1);
                    cm.worldSpouseMessage(37, "【蜡笔潜能】：土豪“" + cm.getPlayer().getName() + "”将『" + cm.getItemName(GID) + "』第[" + h + "]条潜能修改为：" + 潜能描述 + " ");
                    cm.getTopMsgFont("系统提示：修改潜能成功!", 3, 20, 20, 0);
                    cm.effect_NormalSpeechBalloon("修改潜能完毕!", 1, 0, 0, 3000, 0, 0);
                    cm.dispose();
                    return
                } else {
                    cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
            }
        }
    }
}

function action3(f, k, n, d) {
    var l = cm.getConstantScriptContent("菜单_NPC立绘");
    var g = Math.floor(Math.random() * l.length);
    var b = l[g][0];
    var j = randomNum(0, l[g][1]);
    var h = 3;
    var m = 1;
    var c = 3994419;
    if (status <= d++) {
        var a = "#face" + j + "##fn方正粗黑宋简体#";
        a += "  #r基本潜能[1]  #z" + c + "#[" + cm.getItemQuantity(c) + "]#k#fs15#";
        for (var d = 0; d < 潜能列表.length; d++) {
            a += "\r\n#L" + d + "#" + 潜能列表[d][1] + "#k  (消耗： #r" + 潜能列表[d][2] + "#k #k 红色蜡笔)#l"
        }
        cm.askMenu_Bottom(a + " \r\n ", 204, b)
    } else {
        if (status === d++) {
            var o = cm.getEquipBySlot(m);
            if (o == null || o.getGrade(false) != 20) {
                cm.askAcceptDecline_Bottom("#face" + j + "出现错误: \r\n\r\n1、请把#b材料#k放在装备栏#r1#k号位。\r\n2、装备的#b潜能等级#k必须为#rSS#k级。", 204, b);
                cm.dispose();
                return
            }
            var e = 潜能列表[n];
            if (e != null) {
                潜能ID = e[0];
                潜能描述 = e[1];
                费用 = e[2];
                Gitem = cm.getInventory(1).getItem(1);
                cm.askYesNo_Bottom("#face" + j + "#当前选择：#g#v" + Gitem.getItemId() + "##z" + Gitem.getItemId() + "##k \r\n\r\n第#r" + h + "#k条潜能改为：#b[" + 潜能描述 + "#k] 吗？", 204, b)
            } else {
                cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                cm.dispose();
                return
            }
        } else {
            if (status === d++) {
                if (cm.getItemQuantity(c) < 1) {
                    cm.getTopMsgFont("缺少货币无法使用服务。", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
                if (潜能ID <= 0 || 潜能描述 == "" || 费用 <= 0) {
                    cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
                if (cm.changePotential(m, h, 潜能ID, false)) {
                    Gitem = cm.getInventory(1).getItem(1);
                    GID = Gitem.getItemId();
                    ii = cm.getItemInfo();
                    cm.gainItem(c, -1);
                    cm.worldSpouseMessage(37, "【蜡笔潜能】：土豪“" + cm.getPlayer().getName() + "”将『" + cm.getItemName(GID) + "』第[" + h + "]条潜能修改为：" + 潜能描述 + " ");
                    cm.getTopMsgFont("系统提示：修改潜能成功!", 3, 20, 20, 0);
                    cm.effect_NormalSpeechBalloon("修改潜能完毕!", 1, 0, 0, 3000, 0, 0);
                    cm.dispose();
                    return
                } else {
                    cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
            }
        }
    }
}

function action4(f, k, n, d) {
    var l = cm.getConstantScriptContent("菜单_NPC立绘");
    var g = Math.floor(Math.random() * l.length);
    var b = l[g][0];
    var j = randomNum(0, l[g][1]);
    var h = 4;
    var m = 1;
    var c = 3994420;
    if (status <= d++) {
        var a = "#face" + j + "##fn方正粗黑宋简体#";
        a += "  #r基本潜能[1]  #z" + c + "#[" + cm.getItemQuantity(c) + "]#k#fs15#";
        for (var d = 0; d < 潜能列表.length; d++) {
            a += "\r\n#L" + d + "#" + 潜能列表[d][1] + "#k  (消耗： #r" + 潜能列表[d][2] + "#k #k 红色蜡笔)#l"
        }
        cm.askMenu_Bottom(a + " \r\n ", 204, b)
    } else {
        if (status === d++) {
            var o = cm.getEquipBySlot(m);
            if (o == null || o.getGrade(false) != 20) {
                cm.askAcceptDecline_Bottom("#face" + j + "出现错误: \r\n\r\n1、请把#b材料#k放在装备栏#r1#k号位。\r\n2、装备的#b潜能等级#k必须为#rSS#k级。", 204, b);
                cm.dispose();
                return
            }
            var e = 潜能列表[n];
            if (e != null) {
                潜能ID = e[0];
                潜能描述 = e[1];
                费用 = e[2];
                Gitem = cm.getInventory(1).getItem(1);
                cm.askYesNo_Bottom("#face" + j + "#当前选择：#g#v" + Gitem.getItemId() + "##z" + Gitem.getItemId() + "##k \r\n\r\n第#r" + h + "#k条潜能改为：#b[" + 潜能描述 + "#k] 吗？", 204, b)
            } else {
                cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                cm.dispose();
                return
            }
        } else {
            if (status === d++) {
                if (cm.getItemQuantity(c) < 1) {
                    cm.getTopMsgFont("缺少货币无法使用服务。", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
                if (潜能ID <= 0 || 潜能描述 == "" || 费用 <= 0) {
                    cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
                if (cm.changePotential(m, h, 潜能ID, false)) {
                    Gitem = cm.getInventory(1).getItem(1);
                    GID = Gitem.getItemId();
                    ii = cm.getItemInfo();
                    cm.gainItem(c, -1);
                    cm.worldSpouseMessage(37, "【蜡笔潜能】：土豪“" + cm.getPlayer().getName() + "”将『" + cm.getItemName(GID) + "』第[" + h + "]条潜能修改为：" + 潜能描述 + " ");
                    cm.getTopMsgFont("系统提示：修改潜能成功!", 3, 20, 20, 0);
                    cm.effect_NormalSpeechBalloon("修改潜能完毕!", 1, 0, 0, 3000, 0, 0);
                    cm.dispose();
                    return
                } else {
                    cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
            }
        }
    }
}

function action5(f, k, n, d) {
    var l = cm.getConstantScriptContent("菜单_NPC立绘");
    var g = Math.floor(Math.random() * l.length);
    var b = l[g][0];
    var j = randomNum(0, l[g][1]);
    var h = 5;
    var m = 1;
    var c = 3994421;
    if (status <= d++) {
        var a = "#face" + j + "##fn方正粗黑宋简体#";
        a += "  #r基本潜能[1]  #z" + c + "#[" + cm.getItemQuantity(c) + "]#k#fs15#";
        for (var d = 0; d < 潜能列表.length; d++) {
            a += "\r\n#L" + d + "#" + 潜能列表[d][1] + "#k  (消耗： #r" + 潜能列表[d][2] + "#k #k 红色蜡笔)#l"
        }
        cm.askMenu_Bottom(a + " \r\n ", 204, b)
    } else {
        if (status === d++) {
            var o = cm.getEquipBySlot(m);
            if (o == null || o.getGrade(false) != 20) {
                cm.askAcceptDecline_Bottom("#face" + j + "出现错误: \r\n\r\n1、请把#b材料#k放在装备栏#r1#k号位。\r\n2、装备的#b潜能等级#k必须为#rSS#k级。", 204, b);
                cm.dispose();
                return
            }
            var e = 潜能列表[n];
            if (e != null) {
                潜能ID = e[0];
                潜能描述 = e[1];
                费用 = e[2];
                Gitem = cm.getInventory(1).getItem(1);
                cm.askYesNo_Bottom("#face" + j + "#当前选择：#g#v" + Gitem.getItemId() + "##z" + Gitem.getItemId() + "##k \r\n\r\n第#r" + h + "#k条潜能改为：#b[" + 潜能描述 + "#k] 吗？", 204, b)
            } else {
                cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                cm.dispose();
                return
            }
        } else {
            if (status === d++) {
                if (cm.getItemQuantity(c) < 1) {
                    cm.getTopMsgFont("缺少货币无法使用服务。", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
                if (潜能ID <= 0 || 潜能描述 == "" || 费用 <= 0) {
                    cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
                if (cm.changePotential(m, h, 潜能ID, false)) {
                    Gitem = cm.getInventory(1).getItem(1);
                    GID = Gitem.getItemId();
                    ii = cm.getItemInfo();
                    cm.gainItem(c, -1);
                    cm.worldSpouseMessage(37, "【蜡笔潜能】：土豪“" + cm.getPlayer().getName() + "”将『" + cm.getItemName(GID) + "』第[" + h + "]条潜能修改为：" + 潜能描述 + " ");
                    cm.getTopMsgFont("系统提示：修改潜能成功!", 3, 20, 20, 0);
                    cm.effect_NormalSpeechBalloon("修改潜能完毕!", 1, 0, 0, 3000, 0, 0);
                    cm.dispose();
                    return
                } else {
                    cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
            }
        }
    }
}

function action6(f, k, n, d) {
    var l = cm.getConstantScriptContent("菜单_NPC立绘");
    var g = Math.floor(Math.random() * l.length);
    var b = l[g][0];
    var j = randomNum(0, l[g][1]);
    var h = 6;
    var m = 1;
    var c = 3994422;
    if (status <= d++) {
        var a = "#face" + j + "##fn方正粗黑宋简体#";
        a += "  #r基本潜能[1]  #z" + c + "#[" + cm.getItemQuantity(c) + "]#k#fs15#";
        for (var d = 0; d < 潜能列表.length; d++) {
            a += "\r\n#L" + d + "#" + 潜能列表[d][1] + "#k  (消耗： #r" + 潜能列表[d][2] + "#k #k 红色蜡笔)#l"
        }
        cm.askMenu_Bottom(a + " \r\n ", 204, b)
    } else {
        if (status === d++) {
            var o = cm.getEquipBySlot(m);
            if (o == null || o.getGrade(false) != 20) {
                cm.askAcceptDecline_Bottom("#face" + j + "出现错误: \r\n\r\n1、请把#b材料#k放在装备栏#r1#k号位。\r\n2、装备的#b潜能等级#k必须为#rSS#k级。", 204, b);
                cm.dispose();
                return
            }
            var e = 潜能列表[n];
            if (e != null) {
                潜能ID = e[0];
                潜能描述 = e[1];
                费用 = e[2];
                Gitem = cm.getInventory(1).getItem(1);
                cm.askYesNo_Bottom("#face" + j + "#当前选择：#g#v" + Gitem.getItemId() + "##z" + Gitem.getItemId() + "##k \r\n\r\n第#r" + h + "#k条潜能改为：#b[" + 潜能描述 + "#k] 吗？", 204, b)
            } else {
                cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                cm.dispose();
                return
            }
        } else {
            if (status === d++) {
                if (cm.getItemQuantity(c) < 1) {
                    cm.getTopMsgFont("缺少货币无法使用服务。", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
                if (潜能ID <= 0 || 潜能描述 == "" || 费用 <= 0) {
                    cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
                if (cm.changePotential(m, h, 潜能ID, false)) {
                    Gitem = cm.getInventory(1).getItem(1);
                    GID = Gitem.getItemId();
                    ii = cm.getItemInfo();
                    cm.gainItem(c, -1);
                    cm.worldSpouseMessage(37, "【蜡笔潜能】：土豪“" + cm.getPlayer().getName() + "”将『" + cm.getItemName(GID) + "』第[" + h + "]条潜能修改为：" + 潜能描述 + " ");
                    cm.getTopMsgFont("系统提示：修改潜能成功!", 3, 20, 20, 0);
                    cm.effect_NormalSpeechBalloon("修改潜能完毕!", 1, 0, 0, 3000, 0, 0);
                    cm.dispose();
                    return
                } else {
                    cm.getTopMsgFont("出现错误联系管理员", 3, 20, 4, 0, 0);
                    cm.dispose();
                    return
                }
            }
        }
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
};